home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1997 August / Walnut Creek CDROM.7z / LISTINGS / V_13_07 / DAWES.ZIP / COUNT1.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-02  |  561 b   |  27 lines

  1. //  Listing 1 - Count1 program
  2.  
  3. #include <cstring.h>
  4. #include <iomanip.h>
  5. #include <algo.h>
  6. #include <map.h>
  7.  
  8. typedef map< string, long, less<string> > map_t;
  9.  
  10. int main() {
  11.  
  12.   map_t    ct_map;
  13.   string   str;
  14.  
  15.   while ( cin >> str ) {
  16.     ct_map.insert( map_t::value_type(str, 0L) );
  17.     ++ct_map[str];  // increment the count
  18.     }
  19.  
  20.   for ( map_t::const_iterator it = ct_map.begin();
  21.         it != ct_map.end(); ++it )
  22.     { cout << setw(7) << (*it).second
  23.            << " - "   << (*it).first  << endl; }
  24.  
  25.   return EXIT_SUCCESS;
  26.   }
  27.